<!--
 * @Author: krsea 965837746@qq.com
 * @Date: 2025-03-04 15:07:35
 * @LastEditors: krsea 965837746@qq.com
 * @LastEditTime: 2025-03-04 15:53:54
 * @FilePath: \vue3-code\2305\week3\m5像素宽度props.html
 * @Description: 
 * 
 * Copyright (c) 2025 by ${git_name_email}, All Rights Reserved. 
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>组件的基本使用</title>
    <!-- 引入 vue.js -->
    <script src="../js/vue.js"></script>
</head>

<body>
    <!-- div id 为 app 挂载点 -->
    <div id="app">
        <my-cly :width="width"></my-cly>
        <input type="text" v-model="width"></input>
    </div>

    <!-- 定义组件模板 -->
     <template id="temp">
        <div :style="style" style="background-color: yellow;">组件内容宽度{{ width }}px,背景颜色为黄色。</div>
    </template>
    <!-- <div style="background-color: yellow;">组件内容宽度100px,背景颜色为黄色。</div> -->

    <!-- 使用 javascript 脚本 -->
    <script type="text/javascript">
        Vue.component('my-cly', {
            // ... options ...
            props:['width'],
            template: '#temp',
            computed: {
                style: function () {
                    return {
                        width: this.width + 'px'
                    }
                }
            }
        });

        var app = new Vue({
            el: '#app',
            data: {
                width: 120
            }
        });

    </script>
</body>

</html>